// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects.Sdk;

namespace TestValidationAspects.Sdk
{
	[TestFixture]
	public class TestValidatorFactoryExtensions
	{
		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Create_throws_for_null_factory_param()
		{
			ValidatorFactoryExtensions.Create(null, GetType());
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Create_throws_for_null_type_param()
		{
			new MockFactory().Create(null);
		}

		[Test]
		public void Test_Create()
		{
			Validator<double> validator = new Validator<double>((v, c) => { });
			MockFactory factory = new MockFactory {Validator = validator, Type = null};

			Assert.AreSame(validator, factory.Create(typeof(double)));
			Assert.AreSame(typeof(double), factory.Type);
		}

		#region Mocks
		public class MockFactory : IValidatorFactory
		{
			public object Validator { get; set; }
			public Type Type { get; set; }

			#region Implementation of IValidatorFactory
			public IValidator<T> Create<T>()
			{
				Type = typeof(T);
				return (IValidator<T>)Validator;
			}
			#endregion
		}
		#endregion
	}
}